namespace SimpleWebServices.Web.Routing
{
    using SimpleWebServices;
    using SimpleWebServices.Globalization;
    using Xunit;

    public sealed class ResourcePathFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ResourcePath>()
                .DerivesFrom<ValueObject<ResourcePath>>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ResourcePath());
        }

        [Fact]
        public void prop_Extension()
        {
            Assert.True(new PropertyExpectations(typeof(ResourcePath).GetProperty("Extension"))
                .IsAutoProperty<Extension>()
                .Result);
        }

        [Fact]
        public void prop_Language()
        {
            Assert.True(new PropertyExpectations(typeof(ResourcePath).GetProperty("Language"))
                .IsAutoProperty<Language>()
                .Result);
        }

        [Fact]
        public void prop_Name()
        {
            Assert.True(new PropertyExpectations(typeof(ResourcePath).GetProperty("Name"))
                .IsAutoProperty<RouteName>()
                .Result);
        }

        [Fact]
        public void opImplicit_ResourcePath_string()
        {
            ResourcePath expected = new ResourcePath
            {
                Extension = "xhtml",
                Language = "de",
                Name = "test"
            };

            ResourcePath actual = "/test.de.xhtml";

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void opImplicit_ResourcePath_stringEmpty()
        {
            ResourcePath expected = new ResourcePath();
            ResourcePath actual = string.Empty;

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void opImplicit_ResourcePath_stringNull()
        {
            ResourcePath expected = null;
            ResourcePath actual = null as string;

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void opImplicit_string_ResourcePath()
        {
            string expected = "test.de.xhtml";

            string actual = new ResourcePath
            {
                Extension = "xhtml",
                Language = "de",
                Name = "test"
            };

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void opImplicit_string_ResourcePathEmpty()
        {
            string expected = string.Empty;
            string actual = new ResourcePath();

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void opImplicit_string_ResourcePathNull()
        {
            string expected = null as string;
            string actual = null as ResourcePath;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringName()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "test"
            };

            ResourcePath actual = ResourcePath.Parse("/test");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringNameLanguage()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "test",
                Language = "fr"
            };

            ResourcePath actual = ResourcePath.Parse("/test.fr");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringNameLanguageExtension()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "test",
                Language = "fr",
                Extension = "html"
            };

            ResourcePath actual = ResourcePath.Parse("/test.fr.html");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringDottedName()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "foo.bar"
            };

            ResourcePath actual = ResourcePath.Parse("/foo.bar");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringDottedNameLanguage()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "foo.bar",
                Language = "fr"
            };

            ResourcePath actual = ResourcePath.Parse("/foo.bar.fr");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringDottedNameLanguageExtension()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "foo.bar",
                Language = "fr",
                Extension = "html"
            };

            ResourcePath actual = ResourcePath.Parse("/foo.bar.fr.html");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringEmpty()
        {
            ResourcePath expected = new ResourcePath();
            ResourcePath actual = ResourcePath.Parse(string.Empty);

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringNull()
        {
            ResourcePath expected = new ResourcePath();
            ResourcePath actual = ResourcePath.Parse(null);

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringRoot()
        {
            ResourcePath expected = new ResourcePath();
            ResourcePath actual = ResourcePath.Parse("/");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_Parse_stringDirectory()
        {
            ResourcePath expected = new ResourcePath
            {
                Name = "test"
            };

            ResourcePath actual = ResourcePath.Parse("/test/");

            Assert.Equal<ResourcePath>(expected, actual);
        }

        [Fact]
        public void op_ToString()
        {
            ResourcePath obj = new ResourcePath
            {
                Extension = "xhtml",
                Language = "de",
                Name = "test"
            };

            string expected = "test.de.xhtml";
            string actual = obj.ToString();

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToStringEmpty()
        {
            string expected = string.Empty;
            string actual = new ResourcePath().ToString();

            Assert.Equal<string>(expected, actual);
        }
    }
}